package cn.kgc.easybuy.controller;

import cn.kgc.easybuy.annotaion.CheckPermission;
import cn.kgc.easybuy.pojo.Collect;
import cn.kgc.easybuy.service.CollectService;
import cn.kgc.easybuy.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: yingzi-wants-to-sleep
 * @description:
 * @author: 敖成
 * @create: 2025-09-20 09:36
 **/
@RestController
public class CollectController {
    @Autowired
    private CollectService collectService;

    @CheckPermission({"0","1"})
    @PostMapping("/addCollect")
    public AjaxResult addCollect(@RequestBody Collect collect){
        if (collectService.addCollect(collect)){
            return AjaxResult.success();
        }else {
            return AjaxResult.error();
        }
    }
    @CheckPermission({"0","1"})
    @GetMapping("/getCollectList")
    public AjaxResult getCollectList(int userId){
        return AjaxResult.success().add("collects", collectService.getCollectList(userId));
    }

    @CheckPermission({"0","1"})
    @GetMapping("/deleteCollect")
    public AjaxResult deleteCollect(String id,int userId){
        if (collectService.deleteCollect(id,userId)){
            return AjaxResult.success();
        }else {
            return AjaxResult.error();
        }
    }

    @CheckPermission({"0","1"})
    @GetMapping("/deleteAllCollect")
    public AjaxResult deleteAllCollect(int userId){
        if (collectService.deleteAll(userId)){
            return AjaxResult.success();
        }else {
            return AjaxResult.error();
        }
    }
    @CheckPermission({"0","1"})
    @GetMapping("/checkIsCollect")
    public AjaxResult checkIsCollect(Integer pid,Integer userId){
        if (collectService.checkIsCollect(pid,userId)){
            return AjaxResult.success();
        }else {
            return AjaxResult.error();
        }
    }
}
